<?php
/**
 * Created by PhpStorm.
 * User: huyi
 * Date: 2018/1/24
 * Time: 14:51
 * 发布/订阅  生产者
 * 参考地址  :  http://blog.csdn.net/demon3182/article/details/77482725
 */
require_once __DIR__ . './../vendor/autoload.php';use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

$config        = array(
    'localhost',
    5672,
    'huyi',
    'huyi123'
);
$exchange_name = 'logs';
$exchange_type = 'fanout';

$conn    = new AMQPStreamConnection('localhost', 5672, 'huyi', 'huyi123');
$channel = $conn->channel();
//声明一个交换机
$channel->exchange_declare($exchange_name, $exchange_type, false, false, false);
//$argv 是命令行下输入的参数
$data = implode(' ', array_slice($argv, 1));
if(empty($data)){
    $data = 'info : hello how are you';
}

$msg = new AMQPMessage($data);

//消息发布到交换机
$channel->basic_publish($msg, $exchange_name);

echo " [x] Sent ", $data, "\n";

$channel->close();
$conn->close();



